import 'package:app/page/states/home/page_index_state_mixins.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';

class WindowsPageHome extends StatefulWidget {
  const WindowsPageHome({super.key});

  @override
  State<StatefulWidget> createState() {
    return WindowsPageHomeState();
  }
}

class WindowsPageHomeState extends State<WindowsPageHome>
    with PageIndexStateMixins {
  @override
  void initState() {
    super.initState();

    /* Future<String?> result =
        HttpUtil().get("https://sc.api.xiaotuzhi.top/sc/banner/getByType/home");
    result.then(
      (value) {
        Map<String, dynamic> map = jsonDecode(value!);
        var data = jsonDecode(aesDecrypted(map["data"]));
        print(data);
        /* setState(() {
                Map<String, dynamic> map = jsonDecode(value!);
                var data = jsonDecode(aesDecrypted(map["data"]));
                banners.clear();
                for (Map<String, dynamic> element in data) {
                  banners.add(element['imageUrl']);
                }
              }) */
      },
    ).onError((error, stackTrace) {
      print("onError");
    }).catchError((err) {
      print("catchError");
    }); */
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Align(
      alignment: Alignment.topLeft,
      child: SizedBox(
        height: 150,
        width: 280,
        child: Swiper(
          itemCount: banners.length,
          autoplay: true,
          autoplayDelay: 3000,
          itemBuilder: (context, index) {
            return Image.network(
              banners[index],
              fit: BoxFit.cover,
            );
          },
        ),
      ),
    );
  }
}
